package com.lcredu.tx.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author 黎长容
 * @date 2025-07-17 18:33
 */
@Repository
public class GoodsDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public Float queryPriceById(Integer id) {
        String sql = "SELECT price From goods Where goods_id=?";
        Float price = jdbcTemplate.queryForObject(sql, Float.class, id);
        return price;
    }

    public void updateBalance(Integer user_id, Float money) {
        String sql = "UPDATE user_account SET money=money-? Where user_id=?";
        jdbcTemplate.update(sql, money, user_id);
    }

    public void updateAmount(Integer goods_id, int amount) {
        String sql = "UPDATE goods_amount SET goods_num=goods_num-? Where goods_id =?";
        jdbcTemplate.update(sql, amount, goods_id);
    }


    public Float queryPriceById2(Integer id) {
        String sql = "SELECT price From goods Where goods_id=?";
        Float price = jdbcTemplate.queryForObject(sql, Float.class, id);
        return price;
    }

    public void updateBalance2(Integer user_id, Float money) {
        String sql = "UPDATE user_account SET money=money-? Where user_id=?";
        jdbcTemplate.update(sql, money, user_id);
    }

    public void updateAmount2(Integer goods_id, int amount) {
        String sql = "UPDATE goods_amount SET goods_num=goods_num-? Where goods_id =?";
        jdbcTemplate.update(sql, amount, goods_id);
    }


}
